//https://leetcode.cn/problems/compress-string-lcci/

class Solution {
public:
public:
    string compressString(string S)
    {
        if ((int)S.length() == 0)
        {
            return S;
        }
        string ret = "";
        int count = 1;
        char ch = S[0];
        for (int i = 1; i < (int)S.length(); i++)
        {
            if (S[i] == ch)
            {
                count++;
            }
            else
            {
                ret += ch + to_string(count);
                ch = S[i];
                count = 1;
            }
        }
        ret += ch + to_string(count);
        return ret.length() >= S.length() ? S : ret;
    }


};